package entities.userstate;

import entities.User;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * Trabalho PD - 2014/2015
 * @author a21210380 a21210392
 */
@Entity
@Table(name = "awaiting_approval_user")
@NamedQueries({
    @NamedQuery(name = "AwaitingApprovalUser.findAll", query = "SELECT a FROM AwaitingApprovalUser a"),
    @NamedQuery(name = "AwaitingApprovalUser.findByIdUser", query = "SELECT a FROM AwaitingApprovalUser a WHERE a.idUser = :idUser"),
    @NamedQuery(name = "AwaitingApprovalUser.findByHelloMessage", query = "SELECT a FROM AwaitingApprovalUser a WHERE a.helloMessage = :helloMessage")})
public class AwaitingApprovalUser implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "idUser")
    private Integer idUser;
    
    @Size(max = 300)
    @Column(name = "helloMessage")
    private String helloMessage;
    
    @JoinColumn(name = "idUser", referencedColumnName = "idUser", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private User user;

    public AwaitingApprovalUser() {
    }

    public AwaitingApprovalUser(User user, String helloMessage) {
        this.idUser = user.getId();
        this.user = user;
        this.helloMessage = helloMessage;
        this.user.unapproveUser(this);
    }

    public Integer getId() {
        return idUser;
    }

    public String getHelloMessage() {
        return helloMessage;
    }

    public User getUser() {
        return user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUser != null ? idUser.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        if (!(object instanceof AwaitingApprovalUser)) {
            return false;
        }
        AwaitingApprovalUser other = (AwaitingApprovalUser) object;
        return !((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser)));
    }

    @Override
    public String toString() {
        return "entities.userstate.AwaitingApprovalUser[ idUser=" + idUser + " ]";
    }

}
